using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace MoEngine
{
    /// <summary>
    /// Base game class for all the basic game support.
    /// Connects all our helper classes together and makes our life easier!
    /// Note: This game was designed for 16:9 (e.g. 1920x1200), but it
    /// also works just fine for 4:3 (1024x768, 800x600, etc.).
    /// This is the reason you might see 1024x640 instead of 1024x768 in
    /// some width/height calculations and the UI textures.
    /// The game looks best at 1920x1080 (HDTV 1080p resolution).
    /// </summary>
    public partial class GameCore : Game
    {
        //#region Render states
        ///// <summary>
        ///// Alpha blending
        ///// </summary>
        //public static void SetAlphaBlendingEnabled(bool value)
        //{
        //    if (value)
        //    {
        //        Device.RenderState.AlphaBlendEnable = true;
        //        Device.RenderState.SourceBlend = Blend.SourceAlpha;
        //        Device.RenderState.DestinationBlend = Blend.InverseSourceAlpha;
        //    }
        //    else
        //    {
        //        Device.RenderState.AlphaBlendEnable = false;
        //    }
        //}

        ///// <summary>
        ///// Alpha modes
        ///// </summary>
        //public enum AlphaMode
        //{
        //    /// <summary>
        //    /// Disable alpha blending for this (even if the texture has alpha)
        //    /// </summary>
        //    DisableAlpha,
        //    /// <summary>
        //    /// Default alpha mode: SourceAlpha and InvSourceAlpha, which does
        //    /// nothing if the texture does not have alpha, else it just displays
        //    /// it as it is (with transparent pixels).
        //    /// </summary>
        //    Default,
        //    /// <summary>
        //    /// Use source alpha one mode, this is the default mode for lighting
        //    /// effects.
        //    /// </summary>
        //    SourceAlphaOne,
        //    /// <summary>
        //    /// One one alpha mode.
        //    /// </summary>
        //    OneOne,
        //}

        ///// <summary>
        ///// Current alpha mode
        ///// </summary>
        //public static void SetCurrentAlphaMode(AlphaMode value)
        //{
        //    switch (value)
        //    {
        //        case AlphaMode.DisableAlpha:
        //            Device.RenderState.SourceBlend = Blend.Zero;
        //            Device.RenderState.DestinationBlend = Blend.One;
        //            break;
        //        case AlphaMode.Default:
        //            Device.RenderState.SourceBlend = Blend.SourceAlpha;
        //            Device.RenderState.DestinationBlend = Blend.InverseSourceAlpha;
        //            break;
        //        case AlphaMode.SourceAlphaOne:
        //            Device.RenderState.SourceBlend = Blend.SourceAlpha;
        //            Device.RenderState.DestinationBlend = Blend.One;
        //            break;
        //        case AlphaMode.OneOne:
        //            Device.RenderState.SourceBlend = Blend.One;
        //            Device.RenderState.DestinationBlend = Blend.One;
        //            break;
        //    }
        //}
        //#endregion

        #region Constructor

        protected Core m_CoreInst;

        protected MasterWindowGame m_GameWindow;

        public MasterWindowGame MasterWindow
        {
            get { return m_GameWindow; }
        }

        public GraphicsDeviceManager GraphicsManager;

        /// <summary>
        /// Create base game
        /// </summary>
        /// <param name="setWindowsTitle">Set windows title</param>
        protected GameCore()
        {
            m_CoreInst = NewCore(Services);
            Core.Game = this;

            // Set graphics
            // GraphicsManager = new GraphicsDeviceManager(this);
            // Create new window
            m_GameWindow = new MasterWindowGame(this);

        }

        /// <summary>
        /// Initialize
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // Initialize Core
            m_CoreInst.Initialize();

        }
        #endregion

        public virtual Core NewCore(IServiceProvider services)
        {
            return new Core(services);
        }

        #region Update
        /// <summary>
        /// Update
        /// </summary>
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            // Updtae Core
            m_CoreInst.Update(gameTime);

        }
        #endregion

        #region Draw

        /// <summary>
        /// Draw
        /// </summary>
        /// <param name="gameTime">Game time</param>
        protected override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            // Draw Core
            m_CoreInst.Draw(gameTime);
        }

        #endregion
    }
}
